In [ ]:
a=2 # Declaro (defino) el valor de la variable a
In [ ]:
a
In [ ]:
a+a+a+a+a
In [ ]:
a*5
In [ ]:
a * 5
In [ ]:
a*a
In [ ]:
type(a)
In [ ]:
b=1.5
In [ ]:
type(b)
In [ ]:
B=2.5
In [ ]:
print(b,B)
In [ ]:
c='German '
In [ ]:
type(c)
In [ ]:
c
In [ ]:
c+c+c+c+c
In [ ]:
c*5
In [ ]:
c*c
In [ ]:
1<5
In [ ]:
1 < 5
In [ ]:
1<0
In [ ]:
d=(1<5)
In [ ]:
d
In [ ]:
d = (1 < 5)
In [ ]:
d
In [ ]:
type(d)
In [ ]:
2*1.2
In [ ]:
b*c
In [ ]:
a*c
In [ ]:
2*False
In [ ]:
2*True
In [ ]:
2*False
In [ ]:
a<b
In [ ]:
e=(a<b)
In [ ]:
e
In [ ]:
a==b # Son iguales?
In [ ]:
a=b # Re-defino el valor de a, y le asigno el que tiene b
In [ ]:
hoy='Martes'
print(hoy)
hoy='Miércoles'
print(hoy)
hoy='Jueves'
print(hoy)
hoy=3
print(hoy)
In [ ]:
hoy = "Viernes"
hoy = 32.5
hoy = 19
print(hoy)
¿Cómo podemos encontrar el tipo de una variable?
print()
para determinar el tipo mirando el resultado.type()
.print()
sobre el resultado.Si a="10"
y b="Diez"
, se puede decir que a
y b
:
In [ ]:
a='10'
b='Diez'
type(b)
In [ ]:
int(3.14)
In [ ]:
int(3.9999) # Redondea?
In [ ]:
int?
In [ ]:
int
In [ ]:
int(3.0)
In [ ]:
int(3)
In [ ]:
int("12")
In [ ]:
int("twelve")
In [ ]:
float(3)
In [ ]:
float?
In [ ]:
str(3)
In [ ]:
str(3.0)
In [ ]:
str(int(2.9999))
In [ ]:
hola=10
hola
In [ ]:
mi variable=10
In [ ]:
mi_variable=10
In [ ]:
mi-variable=10
In [ ]:
mi.variable=10
In [ ]:
mi$variable=10
In [ ]:
variable_1=34
In [ ]:
1_variable=34
In [ ]:
pi=3.1315
In [ ]:
def=10
Palabras (keywords) que Python no deja usar como nombres para variables:
and as assert break class continue
def del elif else except exec
finally for from global if import
in is lambda nonlocal not or
pass raise return try while with
yield True False None
Este material fue recopilado para Clubes de Ciencia Colombia 2017 por Luis Henry Quiroga (GitHub: lhquirogan) - Germán Chaparro (GitHub: saint-germain), y fue traducido y adaptado de http://interactivepython.org/runestone/static/thinkcspy/index.html
Copyright (C) Brad Miller, David Ranum, Jeffrey Elkner, Peter Wentworth, Allen B. Downey, Chris Meyers, and Dario Mitchell. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with Invariant Sections being Forward, Prefaces, and Contributor List, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.